<!DOCTYPE html>
<html style="height: 100%">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>网站后台管理模版</title>
    <link rel="stylesheet" type="text/css" href="/static/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="/static/admin/css/admin.css"/>
    <script src="/static/admin/layui/lay/modules/layer.js" type="text/javascript"></script>
    <script src="/static/admin/js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
</head>
<body style="height: 100%">
<div class="wrap-container">
    <form class="layui-form" style="width: 90%;padding-top: 20px;">
        <div class="layui-form-item">
            <label class="layui-form-label" th:text="${'学院:'}"></label>
            <div class="layui-input-block">
                <input type="text" name="collegeName" id="collegeName" lay-verify="required"
                       placeholder="请输入学院名称"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script src="/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/admin/js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/admin/js/main.js" type="text/javascript"></script>
<script>
    //Demo
    layui.use(['form', 'laydate'], function () {
        var form = layui.form;
        var laydate = layui.laydate;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            console.log(data.field);
            submitForm(data.field);
            return false;
        });
    });

    function submitForm(date) {
        console.log(JSON.stringify(date));
        $.ajax({
            url: "/college/addCollege.json",
            type: "POST",
            data: JSON.stringify(date),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                var msg = data.message;
                if (data.success) {
                    layer.msg("添加成功",
                        {
                            icon: 1,
                            title: false,
                            time: 1000,
                            area: ['100px', '60px'],
                            closeBtn: 0
                        },
                        function (index) {
                            window.parent.refresh();
                        });
                } else {
                    layer.confirm(msg,
                        {
                            icon: 2,
                            title: false,
                            btn: ['确定'],
                            area: ['100px', '120px'],
                            closeBtn: 0
                        },
                        function (index) {
                            layer.close(index);
                        });
                }
            }
        });
    }
</script>
</body>
</html>